package com.huatai.exchange.utils;

import com.faneui.common.utils.StringUtil;
import com.huatai.exchange.integration.base.service.UserService;
import com.huatai.exchange.integration.base.service.WorkDayService;
import com.huatai.exchange.integration.vba.service.VbaFundNavDayService;
import com.huatai.exchange.integration.webside.service.LiquidateFlowQueryService;
import com.huatai.exchange.service.ExcDataFileInfoService;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.tools.generic.NumberTool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * VelocityContext相关操作，初始化上下文的工具类和报文数据
 */
@Component
public class VelocityContextHelper {


    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private GzFundUtils gzFundUtils;

    @Autowired
    private VbaFundNavDayService VbaFundNavDayService;

    @Autowired
    private WorkDayService workDayService;

    @Autowired
    private ExcDataFileInfoService excDataFileInfoService;

    @Autowired
    private LiquidateFlowQueryService LiquidateFlowQueryService;

    @Autowired
    private GzbUtils gzbUtils;

    @Autowired
    private DateUtils dateUtils;

    @Autowired
    private TaFundUtils taFundUtils;

    @Autowired
    private UserService userService;

    @Autowired
    private O32QueryUtils o32QueryUtils;

    @Autowired
    private SqlUtils sqlUtils;

    @Autowired
    private FlowUtils flowUtils;

    @Autowired
    private FileLoadUtils fileLoadUtils;

    @Autowired
    private TaUtils taUtils;

    /**
     * 填充<code>VelocityContext</code>，包括业务数据对象和相关的工具类
     *
     * @param request
     * @return
     */
    public VelocityContext fillContext(Map<String, Object> request) {

        VelocityContext context = new VelocityContext();
        context.put("req", request);
        // 工具类
        context.put("taFundUtil", taFundUtils);
        context.put("gzFundUtil", gzFundUtils);
        context.put("fundNavUtil", VbaFundNavDayService);
        context.put("userUtil", userService);
        context.put("workDayUtil", workDayService);
        context.put("excDataFileInfoUtil", excDataFileInfoService);
        context.put("LiquidateFlowQueryUtil", LiquidateFlowQueryService);
        context.put("fileLoadUtils", fileLoadUtils);
        context.put("taUtils", taUtils);


        //实现模板嵌套的数据共享
        // 数据 验证类
        context.put("gzbUtil", gzbUtils); // 估值表验证
        context.put("o32QueryUtil", o32QueryUtils);
        context.put("flowUtil", flowUtils);

        context.put("dateUtil", dateUtils);
        context.put("sqlUtil", sqlUtils);
        context.put("stringUtil",new StringUtil()) ;
        context.put("numberTool", new NumberTool());
        context.put("context", context);



        return context;
    }

}
